﻿@page
@{
    ViewData["Title"] = "User List";
}

<div id="app" v-cloak>
    <div class="row">
        <div class="col-12">
            <div class="grid-container">
                <div ref="mainGridRef"></div>
            </div>
        </div>
    </div>

    <div class="modal fade" ref="mainModalRef" id="MainModal" aria-hidden="true" tabindex="-1" data-bs-focus="false" data-bs-backdrop="static">
        <div class="modal-dialog modal-dialog-centered modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">{{ state.mainTitle }}</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <input type="hidden" v-model="state.id" id="Id" name="Id" />
                    <form id="MainForm">
                        <div class="card mb-3">
                            <div class="card-header">
                                <h5>User Info</h5>
                            </div>
                            <div class="card-body">
                                <div class="row mb-2">
                                    <div class="col-md-6">
                                        <label for="FirstName">First Name</label>
                                        <input ref="firstNameRef" v-model="state.firstName">
                                        <label class="text-danger">{{ state.errors.firstName }}</label>
                                    </div>
                                    <div class="col-md-6">
                                        <label for="LastName">Last Name</label>
                                        <input ref="lastNameRef" v-model="state.lastName">
                                        <label class="text-danger">{{ state.errors.lastName }}</label>
                                    </div>
                                </div>

                                <div class="row mb-2">
                                    <div class="col-md-6">
                                        <label for="Email">Email</label>
                                        <input ref="emailRef" v-model="state.email">
                                        <label class="text-danger">{{ state.errors.email }}</label>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-check mt-4">
                                            <input v-model="state.emailConfirmed" id="EmailConfirmed" name="EmailConfirmed" type="checkbox" class="form-check-input">
                                            <label for="EmailConfirmed" class="form-check-label">Email Confirmed</label>
                                        </div>
                                    </div>
                                </div>

                                <div class="row mb-2">
                                    <div class="col-md-6">
                                        <div class="form-check">
                                            <input v-model="state.isBlocked" id="IsBlocked" name="IsBlocked" type="checkbox" class="form-check-input">
                                            <label for="IsBlocked" class="form-check-label">Is Blocked</label>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-check">
                                            <input v-model="state.isDeleted" id="IsDeleted" name="IsDeleted" type="checkbox" class="form-check-input">
                                            <label for="IsDeleted" class="form-check-label">Is Deleted</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div id="PasswordCard" class="card" v-show="!state.id">
                            <div class="card-header">
                                <h5>User Password</h5>
                            </div>
                            <div class="card-body">
                                <div class="row mb-2">
                                    <div class="col-md-6">
                                        <label for="Password">Password</label>
                                        <input v-model="state.password" id="Password" name="Password" type="password" class="form-control" placeholder="Enter Password">
                                        <label class="text-danger">{{ state.errors.password }}</label>
                                    </div>
                                    <div class="col-md-6">
                                        <label for="ConfirmPassword">Confirm Password</label>
                                        <input v-model="state.confirmPassword" id="ConfirmPassword" name="ConfirmPassword" type="password" class="form-control" placeholder="Confirm Password">
                                        <label class="text-danger">{{ state.errors.confirmPassword }}</label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    <button type="button"
                            id="MainSaveButton"
                            class="btn"
                            v-bind:class="state.deleteMode ? 'btn-danger' : 'btn-primary'"
                            v-on:click="handler.handleSubmit"
                            v-bind:disabled="state.isSubmitting">
                        <span class="spinner-border spinner-border-sm me-2" v-if="state.isSubmitting" role="status" aria-hidden="true"></span>
                        <span v-if="!state.isSubmitting">{{ state.deleteMode ? 'Delete' : 'Save' }}</span>
                        <span v-else>{{ state.deleteMode ? 'Deleting...' : 'Saving...' }}</span>
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" ref="changePasswordModalRef" id="ChangePasswordModal" aria-hidden="true" tabindex="-1" data-bs-focus="false" data-bs-backdrop="static">
        <div class="modal-dialog modal-dialog-centered modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">{{ state.changePasswordTitle }}</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <input type="hidden" v-model="state.userId" id="UserId" name="UserId" />
                    <form id="ChangePasswordForm">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="card">
                                    <div class="card-header">
                                        <h5>Password</h5>
                                    </div>
                                    <div class="card-body">
                                        <div class="mb-3">
                                            <label for="NewPassword">New Password</label>
                                            <input v-model="state.newPassword" id="NewPassword" name="NewPassword" type="password" class="form-control" placeholder="Enter new password">
                                            <label class="text-danger">{{ state.errors.newPassword }}</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    <button type="button"
                            id="ChangePasswordSaveButton"
                            class="btn btn-primary"
                            v-on:click="handler.handleChangePassword"
                            v-bind:disabled="state.isChangePasswordSubmitting">
                        <span class="spinner-border spinner-border-sm me-2" v-if="state.isChangePasswordSubmitting" role="status" aria-hidden="true"></span>
                        <span v-if="!state.isChangePasswordSubmitting">Save</span>
                        <span v-else>Saving...</span>
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" ref="changeRoleModalRef" id="ChangeRoleModal" aria-hidden="true" tabindex="-1" data-bs-focus="false" data-bs-backdrop="static">
        <div class="modal-dialog modal-dialog-centered modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">{{ state.changeRoleTitle }}</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <input type="hidden" v-model="state.userId" id="UserId" name="UserId" />
                    <div class="row">
                        <div class="col-md-12">
                            <div class="card">
                                <div class="card-header">
                                    <h5>User Roles</h5>
                                </div>
                                <div class="card-body">
                                    <div class="row">
                                        <div class="col-12">
                                            <div class="grid-container">
                                                <div ref="secondaryGridRef"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts {
    <script src="~/FrontEnd/Pages/Users/UserList.cshtml.js"></script>
}
